package com.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

import com.dao.AccountDaoImpl;
import com.entity.AccountEntity;
import com.entity.LoginEntity;

public class loginVerifyService {

	public String verify(LoginEntity loginEntity) {
		// TODO: 完成账号密码的验证
		// 传入的loginEntity中有用户输入的账号密码信息
		// Return : verify_ok | verify_faild
		
		WebApplicationContext ctx=ContextLoader.getCurrentWebApplicationContext();
		String str;
		if(!loginEntity.getUseraccount().isEmpty()&&!loginEntity.getPassword().isEmpty()) {
			AccountDaoImpl accountDao = (AccountDaoImpl)ctx.getBean("accountDao");
			List <AccountEntity> account=new ArrayList<AccountEntity>();
			str="and userAccount="+"'"+loginEntity.getUseraccount()+"'";
			account=accountDao.findByCondition(str,null,null,true);
			if(account.get(0).getPassword().equals(loginEntity.getPassword())&&account.get(0).getType().equals(loginEntity.getType()))
				return "verify_ok";
		}
		return "verify_faild";
	}
	
}
